package com.zqwh.xtool.model.online;

import android.content.Context;

import com.zqwh.yj.sdk.utils.httpRequest.RetrofitSingleton;
import com.zqwh.yj.sdk.utils.httpRequest.subscribers.NetCallback;
import com.zqwh.yj.sdk.utils.httpRequest.subscribers.ProgressSubscriber;
import com.zqwh.yj.sdk.utils.httpRequest.HttpResultFunc2;
import com.zqwh.xtool.api.online.CheckOrderApi;
import com.zqwh.xtool.config.BaseConfig;
import com.zqwh.xtool.domain.CheckInfo;
import com.zqwh.xtool.model.CheckOrderModel;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.zqwh.xtool.ToolsApp.gUser;

public class CheckOrderModelOnlineImpl implements CheckOrderModel {
    private CheckOrderApi checkOrderApi;
    private Context context;

    public CheckOrderModelOnlineImpl(Context context) {
        this.context = context;
        this.checkOrderApi = RetrofitSingleton.getInstance(BaseConfig.BASE_URL).create(CheckOrderApi.class);
    }

    @Override
    public void submitCheckOrder(Long devId, String orderNo, String epcs, String toolIds, NetCallback<Object> callback) {
        checkOrderApi.submitCheckOrder("Bearer "+gUser.getToken(), devId, orderNo, epcs, toolIds)
                .map(new HttpResultFunc2<Object>())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber(callback, context, false));
    }

    @Override
    public void preSubmit(Long devId, String epcs, NetCallback<CheckInfo> callback) {
        checkOrderApi.preSubmit("Bearer "+gUser.getToken(), devId, epcs)
                .map(new HttpResultFunc2<CheckInfo>())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber(callback, context, false));
    }
}
